package com.gxuwz.business.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gxuwz.business.service.ISysUserRoleService;
import com.gxuwz.business.service.ISysUserService;
import com.gxuwz.util.Result;
import com.gxuwz.util.SystemContext;
import com.gxuwz.business.dao.impl.SysUserDAO;
import com.gxuwz.business.entity.SysRole;
import com.gxuwz.business.entity.SysUser;
import com.gxuwz.business.entity.SysUserRole;

/**
 * 
 * @author Timo
 * 
 */

@Service("sysUserService")
public class SysUserServiceImpl implements ISysUserService {


	
    @Autowired
    private ISysUserRoleService sysUserRoleService;
	@Autowired
	private SysUserDAO sysUserDAO;


	@Override
	public int updateUserPassWd(String userId, String userPassword) {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public boolean checkSign(String userId, String sign) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public SysUser findById(String userId) {
		// TODO Auto-generated method stub
		return sysUserDAO.findById(userId);
	}


	@Override
	public void updateUserMessage(SysUser sysUser, String oldPassword) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public boolean checkUserId(String userId) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean checkPasswd(String rawPassword, String password) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public SysUser findByName(String userName) {
		return sysUserDAO.findByName(userName);
	}


	@Override
	public void add(SysUser sysUser, String[] roleId) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void update(SysUser sysUser, String[] roleId, String oldPassword) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void delete(Integer id, String userId) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public List<String> findUserPermissions(String userId) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public List<SysRole> findRoleByResourcePath(String resourcePath) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public boolean checkUserName(SysUser sysUser) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public void updatePassword(SysUser sysUser, String oldPassword) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public SysUser findByUserId(String userid) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public boolean isLogin(SysUser sysUser) {
		boolean isLogin = false;
		SysUser user = null;
		//通过用户名查找
		user = sysUserDAO.findSysUserByProperty("userName", sysUser.getUserName());
		if(null == user){
			//通过用户id查找
			user = sysUserDAO.findSysUserByProperty("userId", sysUser.getUserId());
		}
		if(null != user){
			//解析密码
			isLogin = SystemContext.passwdDecryption(sysUser.getUserPassword(), user.getUserPassword());
		}
		return isLogin;
	}


	@Override
	public List<Object> findUserByUserIdAndSign(String userId, String sign) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public boolean isTrue(SysUser sysUser) {
		boolean isLogin = false;
		SysUser user = null;
		//通过用户名查找
		user = sysUserDAO.findSysUserByProperty("userId", sysUser.getUserId());
		if(null != user){
			//解析密码
			isLogin = SystemContext.passwdDecryption(sysUser.getUserPassword(), user.getUserPassword());
		}
		return isLogin;
	}


	@Override
	public boolean updatePassword(String newPassword,SysUser sysUser) {
		// TODO Auto-generated method stub
		return sysUserDAO.updatePassword(newPassword,sysUser);
	}


	@Override
	public boolean update(SysUser user) {
		return sysUserDAO.update(user);
	}

	@Override
	public Result uploadUserFace(SysUser sysUser) {
		return sysUserDAO.updateUserFace(sysUser);
	}

}
